package com.xiaodu.jpa.entity;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * @author: dutianjie
 * @date: 2021/4/21
 * @version: v1.0.0
 * @description: 描述
 **/
@Table(name = "t_order")
@Entity
public class OrderEntity {

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    // 会自动创建中间表 order_product，通过 joinColumns 中关联了自己的orderNo 和中间表的orderNo(referencedColumnName引用自己的那个字段)
    // 通过inverseJoinColumns 关联了 中间表和关联的Product 表的字段关系
    @JoinTable(name = "order_product", joinColumns = {@JoinColumn(name = "orderNo", referencedColumnName = "orderNo")},
            inverseJoinColumns = {@JoinColumn(name = "pId", referencedColumnName = "pId")})
// 外键关联，会在 product 表中生产order_no字段；
//    @JoinColumn(name = "orderNo", referencedColumnName = "orderNo")
    private Set<ProductEntity> productEntities;


    @Id
    @Column(length = 32)
    private String orderNo;

    @Column(unique = true, nullable = false)
    private Date createTime;


    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Set<ProductEntity> getProductEntities() {
        return productEntities;
    }

    public void setProductEntities(Set<ProductEntity> productEntities) {
        this.productEntities = productEntities;
    }
}
